package com.ymm.handler.meta;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ymm.enums.SystemContains;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class YmmMetaObjectHandler implements MetaObjectHandler {
    /**
     * 数据插入时候自动填入
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(System.currentTimeMillis()), metaObject);
        this.setFieldValByName("updateTime", new Date(System.currentTimeMillis()), metaObject);
        this.setFieldValByName("createBy", SystemContains.ADMIN_NAME, metaObject);
        this.setFieldValByName("updateBy", SystemContains.ADMIN_NAME, metaObject);
    }

    /**
     * 数据更新的时候自动填入
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(System.currentTimeMillis()), metaObject);
        this.setFieldValByName("updateBy", SystemContains.ADMIN_NAME, metaObject);
    }
}
